package de.jmda.gen.java.impl;

import java.util.LinkedList;
import java.util.List;

import de.jmda.gen.Generator;
import de.jmda.gen.impl.AbstractCompoundGenerator;
import de.jmda.gen.java.PackageStatementGenerator;
import de.jmda.gen.java.DeclaredPackageGenerator;

/**
 * @author rwegner
 */
public abstract class AbstractDeclaredPackageGenerator
		extends AbstractCompoundGenerator
		implements DeclaredPackageGenerator
{
	private PackageStatementGenerator packageStatementGenerator;

	public AbstractDeclaredPackageGenerator(
			PackageStatementGenerator packageStatementGenerator)
	{
		super();

	  if (packageStatementGenerator == null)
	  {
	  	throw new IllegalArgumentException(
	  			"'packageStatementGenerator' must not be null");
	  }

	  this.packageStatementGenerator = packageStatementGenerator;
	}

	/**
	 * Returns collection of <code>Generator</code>s with the return values of the
	 * following methods in the following order:
	 * <ul>
	 *   <li>{@link #getPackageStatementGenerator()}</li>
	 * </ul>
	 *
	 * @see de.jmda.gen.CompoundGenerator#getGeneratorComponents()
	 */
	@Override
	public List<Generator> getGeneratorComponents()
	{
		List<Generator> result = new LinkedList<Generator>();
		
		result.add(getPackageStatementGenerator());

		return result;
	}

	/**
	 * @return {@link #packageStatementGenerator}, may be <code>null</code> because
	 *         modifiers are optional.
	 *
	 * @see de.jmda.gen.java.DeclaredPackageGenerator#getPackageStatementGenerator()
	 */
	@Override
  public PackageStatementGenerator getPackageStatementGenerator()
  {
		return packageStatementGenerator;
  }

	@Override
	public void setPackageStatementGenerator(PackageStatementGenerator packageStatementGenerator)
  {
	  if (packageStatementGenerator == null)
	  {
	  	return;
	  }

	  this.packageStatementGenerator = packageStatementGenerator;
  }
}